/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.perlak.camel.search;

import com.google.protobuf.ByteString;
import com.perlak.filesearch.FileSearchRequest;
import com.perlak.filesearch.SingleFileResult;
import com.perlak.messages.FileSearch.fileSearchRequest;
import com.perlak.messages.FileSearch.singleFileResult;
import com.perlak.tools.DateUtil;

/**
 *
 * @author mateusz
 */
public final class SearchMessageTranslator {

  public static FileSearchRequest translate(final fileSearchRequest request) {
    return new FileSearchRequest(request.getSearchName(), request.getFullDirPath(), request.getSource());
  }
  public static fileSearchRequest translate(final FileSearchRequest request) {
    fileSearchRequest.Builder builder = fileSearchRequest.newBuilder();
    builder.setFullDirPath(request.getFullDirPath());
    builder.setSearchName(request.getSearchName());
    builder.setSource(request.getSource());
    return builder.build();
  }
  
  public static singleFileResult translate(final SingleFileResult fsSingleRes) {
    singleFileResult.Builder sfResBuild = singleFileResult.newBuilder();
    sfResBuild.setDirectoryAt(fsSingleRes.getDirectoryAt());
    sfResBuild.setDtModified(DateUtil.calendarToString(fsSingleRes.getDtModified()));
    sfResBuild.setExtension(fsSingleRes.getExtension());
    sfResBuild.setFileSize(fsSingleRes.getFileSize());
    sfResBuild.setFullpath(fsSingleRes.getFullpath());
    sfResBuild.setHash(ByteString.copyFrom(fsSingleRes.getHash()));
    sfResBuild.setHidden(false); // todo add hidden
    sfResBuild.setName(fsSingleRes.getName());
    sfResBuild.setSource(fsSingleRes.getSource());
    return sfResBuild.build();
  }
}
